﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JmShared
{
    public class SharedStaticMethods
    {
        public static DeviceType GetDeviceType(string userID)
        {
            try
            {
                int index = userID.IndexOf("#", StringComparison.Ordinal);
                string str = userID.Substring(index);
                if (str.StartsWith("#wp"))
                    return DeviceType.WindowsPhone;
                else if (str.StartsWith("#android"))
                    return DeviceType.Android;
                else
                    return DeviceType.PC;
            }
            catch (Exception e)
            {
                throw;
            }
        }
        public static List<string> SplitLongMessage(string str, int chunkSize)
        {
            if (str.Length < chunkSize)
                return null;
            int totalLength = str.Length;
            List<string> strList = new List<string>();
            int i = 0;
            while (true)
            {
                if ((totalLength - i) < chunkSize)
                {
                    strList.Add(str.Substring(i, totalLength - i));
                    break;
                }
                string sub = str.Substring(i, chunkSize);
                int lastSpaceIndex = sub.LastIndexOf(' ');
                if (lastSpaceIndex == -1)
                    lastSpaceIndex = chunkSize;

                strList.Add(str.Substring(i, lastSpaceIndex));
                i += lastSpaceIndex;


            }
            return strList;
        }
    }

}
